package com.zhongfl.crm.lixiao.common;

import java.util.*;

/**
 * ListUtils List集合工具类
 *
 * @author tiantian
 * @email zhou.wenbin@zhongfl.com
 * @date 2018/8/28 10:58
 */
public class ListUtils {

    /**
     * 需要新增
     */
    public static final String INCREASE = "increase";

    /**
     * 需要去掉
     */
    public static final String DECREASE = "decrease";

    /**
     * 取两个集合中去除交集的部分
     * 外部list A独有部分需要增加:A-B
     * 本地list B独有部分需要去掉:B-A
     *
     * @param externalList 外部list
     * @param localList    本地list
     * @return 需要修改的数据map集合
     */
    public static Map<String, String> getDifferentSetFromTwoList(List<String> externalList, List<String> localList) {
        Map<String, String> resultMap = new HashMap<>(0);

        Set<String> localSet = new HashSet<>(localList);
        // 1. 取A-B
        externalList.forEach(s -> {
            if (!localSet.contains(s)) {
                resultMap.put(s, INCREASE);
            }
        });

        Set<String> externalSet = new HashSet<>(externalList);
        // 2. 取B-A
        localList.forEach(s -> {
            if (!externalSet.contains(s)) {
                resultMap.put(s, DECREASE);
            }
        });

        return resultMap;
    }
}
